






<!doctype html>
<html lang="zh-CN">
<head>
  <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <meta name="author" content="Chasing Dreams yu">
  
  
  
  
    <meta name="description" content="一、基于 Laravel-Admin 在十分钟内搭建起功能齐全的后台模板1、简介Laravel-Admin为 Laravel 提供后台模板的项目越来越多，学院君已陆续为大家介绍过Laravel Angular Admin、LaraAdmin、Voyager等，网友也贡献了很多后台模板，这对 Laravel 生态来说自然是好事，今天学院君还要给大家介绍一个后台模板扩展包，其官方文档号称可以帮助...">
  
  <title>laravel工具篇 [ 追梦的少年丶 ]</title>
  
  
    <link rel="shortcut icon" href="/besyu/favicon.ico">
  
  
  <link rel="stylesheet" href="/besyu/css/random.css">
<link rel="stylesheet" href="/besyu/css/vegas.min.css">
<link rel="stylesheet" href="/besyu/css/highlight-railscasts.css">
<link rel="stylesheet" href="/besyu/css/jquery.fancybox.css">
<link rel="stylesheet" href="/besyu/css/iconfont/iconfont.css">
<link rel="stylesheet" href="/besyu/css/jquery.fancybox-thumbs.css">
<link rel="stylesheet" href="/besyu/css/plyr.css">
  
</head>

<body>
<div class="side-navigate hide-area">
  
    <div class="item prev">
      <a href="/besyu/2017/04/04/memcache/">
        <div class="item-icon"></div>
      </a>
      <div class="item-title">
        memcache
      </div>
    </div>
  
  
</div>
<div id="outer-container" class="hide-area">
<div id="container">
  <div id="menu-outer" class="slide-down">
    <div id="menu-inner">
      <div id="brand">
        
        <a onClick="openUserCard()">
          <img id="avatar" src="http://7te9fe.com1.z0.glb.clouddn.com/default_avatar.jpg"/>
          <div id="homelink">追梦的少年丶</div>
        </a>
      </div>
      <div id="menu-list">
        <ul>
        
        
          
            <li>
          
            <a href="/besyu/index.html">首页</a>
            
          </li>
        
          
            <li>
          
            <a href="/besyu/archives">归档</a>
            
          </li>
        
          
            <li>
          
            <a href="/besyu/tags">标签</a>
            
          </li>
        
          
            <li>
          
            <a href="/besyu/categories">分类</a>
            
          </li>
        
          
            <li>
          
            <a href="/besyu/about">关于我</a>
            
          </li>
        
        </ul>
      </div>
      <div id="show-menu">
        <button>Menu</button>
      </div>
    </div>
  </div>

  <div id="content-outer">
    <div id="content-inner">
      
      
  <article id="post">
    <h1>laravel工具篇</h1>
    <p class="page-title-sub">
      <span id = "post-title-date">撰写于 2017-04-05</span>
      
        <span id = "post-title-updated">修改于 2017-04-05</span>
      
      
      
    </p>
    
    <h2 id="一、基于-Laravel-Admin-在十分钟内搭建起功能齐全的后台模板"><a href="#一、基于-Laravel-Admin-在十分钟内搭建起功能齐全的后台模板" class="headerlink" title="一、基于 Laravel-Admin 在十分钟内搭建起功能齐全的后台模板"></a>一、基于 Laravel-Admin 在十分钟内搭建起功能齐全的后台模板</h2><h3 id="1、简介"><a href="#1、简介" class="headerlink" title="1、简介"></a>1、简介</h3><p><a href="http://z-song.github.io/laravel-admin/#/zh/quick-start" target="_blank" rel="external">Laravel-Admin</a><br>为 Laravel 提供后台模板的项目越来越多，学院君已陆续为大家介绍过Laravel Angular Admin、LaraAdmin、Voyager等，网友也贡献了很多后台模板，这对 Laravel 生态来说自然是好事，今天学院君还要给大家介绍一个后台模板扩展包，其官方文档号称可以帮助大家在十分钟内构建器功能完备的 Laravel 应用后台。接下来，让我们来一窥究竟吧。</p>
<p>laravel-admin 是一个用于为Laravel提供后台界面的构建器，仅仅通过数行代码，就可以帮助我们构建CRUD后台。</p>
<p>演示地址：<a href="http://120.26.143.106/admin" target="_blank" rel="external">http://120.26.143.106/admin</a></p>
<h3 id="2、安装"><a href="#2、安装" class="headerlink" title="2、安装"></a>2、安装</h3><blockquote>
<p>注：安装前确保数据库连接配置正确。<br>以下是不同版本 Laravel 下 Composer 安装命令：</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">Laravel 5.2</div><div class="line">composer require encore/laravel-admin &quot;dev-master&quot;</div><div class="line"></div><div class="line">Laravel 5.3</div><div class="line">composer require encore/laravel-admin &quot;1.3.x-dev&quot;</div><div class="line"></div><div class="line">Laravel 5.1</div><div class="line">composer require encore/laravel-admin &quot;1.1.x-dev&quot;</div></pre></td></tr></table></figure>
<p>在config/app.php中注册服务提供者：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Encore\Admin\Providers\AdminServiceProvider::class</div></pre></td></tr></table></figure>
<p>然后运行以下命令完成安装：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">php artisan vendor:publish --tag=laravel-admin</div><div class="line">php artisan admin:install</div></pre></td></tr></table></figure>
<p>在浏览器中访问<a href="http://localhost/admin/，使用admin/admin登录到后台。" target="_blank" rel="external">http://localhost/admin/，使用admin/admin登录到后台。</a></p>
<p>配置文件位于config/admin.php，如果需要的话，可以打开该文件进行自定义配置。</p>
<h3 id="3、快速入门"><a href="#3、快速入门" class="headerlink" title="3、快速入门"></a>3、快速入门</h3><p>接下来我们以users表为例讲解该扩展包的使用，该数据表的结构如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">CREATE TABLE `users` (</div><div class="line">    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,</div><div class="line">    `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,</div><div class="line">    `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,</div><div class="line">    `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL,</div><div class="line">    `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,</div><div class="line">    `created_at` timestamp NOT NULL DEFAULT &apos;0000-00-00 00:00:00&apos;,</div><div class="line">    `updated_at` timestamp NOT NULL DEFAULT &apos;0000-00-00 00:00:00&apos;,</div><div class="line">    PRIMARY KEY (`id`),</div><div class="line">    UNIQUE KEY `users_email_unique` (`email`)</div><div class="line">) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci</div></pre></td></tr></table></figure>
<p>该数据表对应的模型App\User.php。</p>
<p>下面我们来看下如何实现CRUD页面</p>
<ul>
<li>添加控制器<blockquote>
<p>我们使用如下Artisan命令为User模型创建对应的控制器：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">php artisan admin:make UserController --model=App\\User</div></pre></td></tr></table></figure>
</blockquote>
</li>
</ul>
<p>生成的控制器位于app/Admin/Controllers/UserController.php</p>
<ul>
<li>添加路由<blockquote>
<p>在app/Admin/routes.php中添加路由：</p>
</blockquote>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$router-&gt;resource(&apos;users&apos;, UserController::class);</div></pre></td></tr></table></figure>
<ul>
<li>添加左侧菜单项<blockquote>
<p>打开<a href="http://localhost/admin/auth/menu，添加菜单链接并刷新页面，就会看到左侧菜单条" target="_blank" rel="external">http://localhost/admin/auth/menu，添加菜单链接并刷新页面，就会看到左侧菜单条</a></p>
</blockquote>
</li>
<li>构建格子和表单<blockquote>
<p>接下来要做的是打开app/Admin/Contollers/UserController.php，找到grid和form方法，并通过model-grid和model-form编写自己的代码。</p>
</blockquote>
</li>
<li>第三方组件<blockquote>
<p>laravel-admin使用了以下第三方插件和服务：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">Laravel</div><div class="line">AdminLTE</div><div class="line">Bootstrap Markdown</div><div class="line">Datetimepicker</div><div class="line">CodeMirror</div><div class="line">font-awesome</div><div class="line">moment</div><div class="line">Google map</div><div class="line">Tencent map</div><div class="line">bootstrap-fileinput</div><div class="line">jquery-pjax</div><div class="line">Nestable</div><div class="line">noty</div></pre></td></tr></table></figure>
</blockquote>
</li>
</ul>
<h2 id="二、信息返回的提示消息"><a href="#二、信息返回的提示消息" class="headerlink" title="二、信息返回的提示消息"></a>二、信息返回的提示消息</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">return redirect()-&gt;back()-&gt;withInput()-&gt;withErrors(&apos;删除成功！&apos;);</div><div class="line">@if (count($errors) &gt; 0)</div><div class="line">                            &lt;div class=&quot;alert alert-danger&quot;&gt;</div><div class="line">                                &#123;!! implode(&apos;&lt;br&gt;&apos;, $errors-&gt;all()) !!&#125;</div><div class="line">                            &lt;/div&gt;</div><div class="line">                        @endif</div></pre></td></tr></table></figure>

  </article>
  <div class="random-toc-area">
  <button class="btn-hide-toc btn-hide-toc-show" style="display: none" onclick="TOCToggle()">显示目录</button>
  <button class="btn-hide-toc btn-hide-toc-hide" onclick="TOCToggle()">隐藏目录</button>
  <div class="random-toc">
    <h2>目录</h2>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、基于-Laravel-Admin-在十分钟内搭建起功能齐全的后台模板"><span class="toc-text">一、基于 Laravel-Admin 在十分钟内搭建起功能齐全的后台模板</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1、简介"><span class="toc-text">1、简介</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2、安装"><span class="toc-text">2、安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3、快速入门"><span class="toc-text">3、快速入门</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、信息返回的提示消息"><span class="toc-text">二、信息返回的提示消息</span></a></li></ol>
  </div>
</div>

  
<nav id="pagination">
  
    <a href="/besyu/2017/04/04/memcache/" class="prev">&larr; 上一篇 memcache</a>
  

  

  
</nav>

  <!-- JiaThis Button BEGIN -->

<!-- JiaThis Button END -->


      
      
      
    </div>
  </div>

  <div id="bottom-outer">
    <div id="bottom-inner">
      Site by Chasing Dreams yu using
      <a href="http://hexo.io">Hexo</a> & <a href="https://github.com/stiekel/hexo-theme-random">Random</a>
      <br>
      
    </div>
  </div>
</div>

</div>



<div id="user-card">
  <div class="center-field">
    <img class="avatar" src="http://7te9fe.com1.z0.glb.clouddn.com/default_avatar.jpg">
    <p id="description"></p>
    <ul class="social-icon">
  
  
    <li>
      <a href="https://github.com/stiekel/hexo-theme-random">
        
          <i class="icon iconfont github">&#xe606;</i>
        
      </a>
    </li>
  
    <li>
      <a href="https://coding.net/u/Stiekel">
        
          <i class="icon iconfont coding">&#xe607;</i>
        
      </a>
    </li>
  
    <li>
      <a href="https://twitter.com/SidCN">
        
          <i class="icon iconfont twitter">&#xe600;</i>
        
      </a>
    </li>
  
    <li>
      <a href="http://weibo.com/sidcn">
        
          <i class="icon iconfont weibo">&#xe602;</i>
        
      </a>
    </li>
  
    <li>
      <a href="http://www.douban.com/people/Stiekel/">
        
          <i class="icon iconfont douban">&#xe60f;</i>
        
      </a>
    </li>
  
</ul>
  </div>
</div>


<div id="btn-view">Hide</div>

<script>
// is trigger analytics / tongji script
var isIgnoreHost = false;

if(window && window.location && window.location.host) {
  isIgnoreHost = ["localhost","127.0.0.1"].some(function(address){
    return 0 === window.location.host.indexOf(address);
  });
}

var isTriggerAnalytics = !( true && isIgnoreHost );

</script>




  
  
    <script src="/besyu/js/jquery-2.2.3.min.js"></script>
  
    <script src="/besyu/js/vegas.min.js"></script>
  
    <script src="/besyu/js/random.js"></script>
  
    <script src="/besyu/js/highlight.pack.js"></script>
  
    <script src="/besyu/js/jquery.mousewheel.pack.js"></script>
  
    <script src="/besyu/js/jquery.fancybox.pack.js"></script>
  
    <script src="/besyu/js/jquery.fancybox-thumbs.js"></script>
  
    <script src="/besyu/js/plyr.js"></script>
  

<script>

  // fancybox
  var backgroundImages = [];
  
  $('#post').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox') || $(this).parent().hasClass('fancybox-thumb')) return;
      var alt = this.alt || this.title;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'post' + i);
    });
  });
  $(".fancybox").fancybox();

var vegasConfig = {"preload­Image":true,"transition":["slideLeft2","slideRight2","flash2"],"timer":true,"delay":5000,"shuffle":true,"count":28};
var unsplashConfig = {"gravity":"north"};
// is show background images
var turnoffBackgroundImage = false;



  turnoffBackgroundImage = true;


var backgroundColor = "34495E";

$(".fancybox-thumb").fancybox({
  prevEffect: 'none',
  nextEffect: 'none',
  helpers: {
    title: {
      type: 'outside'
    },
    thumbs: {
      width: 50,
      height: 50
    }
  }
});

// show video with plyr
$(".video-container iframe").each(function(i){
  var url = $(this).attr('src');
  var id = url.split('/').pop();
  var plyrContainer = document.createElement('div');
  plyrContainer.className = 'plyr';
  var plyrElement = document.createElement('div');
  plyrElement.dataset.videoId = id;
  switch(true) {
    case url.search('youtube.com') >= 0:
      plyrElement.dataset.type = 'youtube';
      break;
    case url.search('vimeo.com') >= 0:
      plyrElement.dataset.type = 'vimeo';
      break;
    default:
      return;
  };
  plyrContainer.appendChild(plyrElement);
  $(this).parent().html(plyrContainer);
});
plyr.setup('.plyr', {iconUrl: '/besyu/css/sprite.svg'});
</script>
</body>
</html>

